// pages/result/result.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
			items:[
				{	
					Name:'',
					count:0,			
				}
			],
			isSaved:false,
			takingPhoto:'',
			img:'/icon/相机.png',
			currentImage:'/icon/收藏.png',
			saved:'/icon/收藏-选中.png',
			notSaved:'/icon/收藏.png',
			time:'2024-8-25'
		},
		saveThis: function(event) {
		// let isSaved = this.data.items.isSaved
		if (this.data.isSaved==false) {
			this.setData({
			isSaved:true
    });
		}	else{
			this.setData({
			isSaved:false
    });
		}
		console.log(this.data.items);
		// wx.setStorageSync('saving', this.data.isSaved);
		const s = wx.getStorageSync('takingPhoto');
		this.setData({
			takingPhoto:s
		})
    wx.request({
      url: 'http://localhost:8001/record/saveRecord',//连接服务器
      method: 'POST',
      data: {
        isSaved: this.data.isSaved,
				manipulatePicture:this.data.takingPhoto,
				species:this.data.items.Name,
				counts:this.data.items.count,
				finishTime:this.data.time
      },
      success: function(res) {
        console.log('保存成功');
      },
      fail: function(err) {
        console.error('保存失败', err);
      }
    });
  },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
		wx.request({
    url: 'http://localhost:8001/record/saveRecord',
    method: 'GET',
    success: (res) => {  
        console.log('请求成功');
        this.setData({
					isSaved:isSaved,
					'items.Name':species,
					'items.count':counts,
					time:finishTime,
					takingPhoto:manipulatePicture
        });
    },
    fail: (err) => { 
        console.error('请求失败', err);
    }
  });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
			wx.request({
      url: 'http://localhost:8001/record/saveRecord',//连接服务器
      method: 'POST',
      data: {
        isSaved: this.data.isSaved,
				manipulatePicture:this.data.takingPhoto,
				species:this.data.items.Name,
				counts:this.data.items.count,
				finishTime:this.data.time
      },
      success: function(res) {
        console.log('保存成功');
      },
      fail: function(err) {
        console.error('保存失败', err);
      }
    });
    wx.request({
    url: 'http://localhost:8001/record/saveRecord',
    method: 'GET',
    success: (res) => {  
        console.log('请求成功');
        this.setData({
					isSaved:isSaved,
					'items.Name':species,
					'items.count':counts,
					time:finishTime,
					takingPhoto:manipulatePicture
        });
    },
    fail: (err) => { 
        console.error('请求失败', err);
    }
  });
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})